package org.fly.bean;

import java.util.List;

/**
 * Created by Administrator on 2016/5/18.
 */
public class Page {

    private int pageNo;
    private int pageTotal;
    private int pageSize = 10;
    private long total;
    private List<?> data;
    private int start;


    public Page(int pageNo, int pageSize){
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.start = pageStart();
    }

    private int pageStart(){
        if(pageNo<1)
            pageNo = 1;
        return (pageNo-1)*pageSize;
    }

    public Page(int pageNo, int total, int pageSize, List<?> data){
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.data = data;
        this.total = total;
        this.pageTotal = pageTotal();
    }

    public Page(int pageNo, int total, List<?> data){
        this.pageNo = pageNo;
        this.data = data;
        this.total = total;
        this.pageTotal = pageTotal();
    }



    private int pageTotal(){
        if((total%pageSize)!=0){
            return (int) (total/pageSize+1);
        }else{
            return (int) (total/pageSize);
        }
    }


    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
        this.pageTotal = pageTotal();
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public long getPageTotal() {
        return pageTotal;
    }

    public void setPageTotal(int pageTotal) {
        this.pageTotal = pageTotal;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public List<?> getData() {
        return data;
    }

    public void setData(List<?> data) {
        this.data = data;
    }

    public int getStart() {
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }
}
